/**
 * 顶部信息提示面板
 */

//--------------------------------------------------------------------------
//
//	初始化
//
//--------------------------------------------------------------------------
var infopad = null;

//页面载入初始化
$( "body" ).ready( function( e )
{
	infopad = new InfoPad();
	infopad.init();
} );

//--------------------------------------------------------------------------
//
//	智能提交表单系统类
//
//--------------------------------------------------------------------------

function InfoPad()
{
	this.html = "<div id='__INFO_PAD' style='border:1px solid #666;background:#ffe;padding:10px 30px 10px 30px;font-size:16px;position:fixed;top:0;left:300px;z-index:99999;-moz-border-radius: 4px;-khtml-border-radius: 4px;-webkit-border-radius: 4px;border-radius: 4px;'></div>";

	// 初始化
	this.init = function()
	{
		$( "body" ).append( this.html );
	
		$( "#__INFO_PAD" ).hide();
		//this.show( "信息提示模块初始化" );
	};

	// 显示单条信息
	this.show = function( msg, color, delay,t)
	{
		if( color == undefined )
			color = "#333333";
		
		$( "#__INFO_PAD" ).click(function(){
			$(this).hide();
		});
		
		$( "#__INFO_PAD" ).css( "width", "auto" );
		$( "#__INFO_PAD" ).css( "color", color );
		$( "#__INFO_PAD" ).alpha( 0.95 );
		$( "#__INFO_PAD" ).html( msg );

		var bw = $( window ).width();
		var dw = $( "#__INFO_PAD" ).width();

		if( dw > 600 )
			dw = 600;

		if( dw > bw )
			dw = parseInt( bw * 0.9 );

		$( "#__INFO_PAD" ).width( dw );

		var dh = $( "#__INFO_PAD" ).outerHeight() + 22;
		var dx = parseInt( ( bw - $( "#__INFO_PAD" ).outerWidth( true ) ) * 0.5 );

		delay = typeof ( delay ) == "undefined" ? 2000 : delay * 1000;

		$( "#__INFO_PAD" ).finish();
		$( "#__INFO_PAD" ).show();
		$( "#__INFO_PAD" ).move( dx, 2 );
		$( "#__INFO_PAD" ).delay( delay ).animate( { top:t?0:-dh }, 200, function()
		{ 
			
			if(t){
				
				$( "#__INFO_PAD" ).show();
				
			}else{
				$( "#__INFO_PAD" ).hide();
			}
			
		} );
	};

	/**
	 * 提示错误信息
	 * 
	 * @param msg 提示内容
	 * @param delay 停留时间（单位：秒）
	 */
	this.err = function( msg, delay )
	{
		this.show( msg, "#dd0000", delay );
	};

	this.msg = function( msg, delay )
	{
		this.show( msg, "#77cc00", delay );
	};
  
	this.errs = function( msg, delay, t)
	{
		this.show( msg, "#dd0000", delay,t);
	};
	
	this.warn = function( msg, delay )
	{
		this.show( msg, "#cc9900", delay );
	};
}
